import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from matplotlib import pyplot
# model
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import Ridge
from sklearn.linear_model import Lasso
from sklearn.linear_model import MultiTaskLasso
from sklearn.linear_model import ElasticNet
from sklearn.linear_model import MultiTaskElasticNet
from sklearn.linear_model import Lars
from sklearn.linear_model import LassoLars
from sklearn.linear_model import OrthogonalMatchingPursuit
from sklearn.linear_model import BayesianRidge
from sklearn.linear_model import ARDRegression
from sklearn.linear_model import SGDRegressor
from sklearn.linear_model import PassiveAggressiveRegressor
from sklearn.linear_model import HuberRegressor
from sklearn.preprocessing import PolynomialFeatures
from sklearn.kernel_ridge import KernelRidge
from sklearn.svm import SVR
from sklearn.svm import NuSVR
from sklearn.svm import LinearSVR
from sklearn.neighbors import KNeighborsRegressor
from sklearn.neighbors import RadiusNeighborsRegressor
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import BaggingRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import ExtraTreesRegressor
from sklearn.ensemble import AdaBoostRegressor
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.semi_supervised import LabelSpreading
from sklearn.isotonic import IsotonicRegression




# read data
train_data=pd.read_csv('train_dataset.csv')
train_price=train_data['PRICE']
del train_data['PRICE']
x_train,x_test,y_train,y_test=train_test_split(train_data,train_price,test_size=0.3,random_state=7)
# 记录结果
results=[]
names=[]

models=[]
models.append(('LinearRegression',LinearRegression()))
models.append(('Ridge',Ridge()))
models.append(('Lasso',Lasso()))
# models.append(('MultiTaskLasso',MultiTaskLasso()))# mono-output
models.append(('ElasticNet',ElasticNet()))
# models.append(('MultiTaskElasticNet',MultiTaskElasticNet()))#For mono-task outputs
models.append(('Lars',Lars()))
models.append(('LassoLars',LassoLars()))
models.append(('OrthogonalMatchingPursuit',OrthogonalMatchingPursuit()))
models.append(('BayesianRidge',BayesianRidge()))
models.append(('ARDRegression',ARDRegression()))
models.append(('SGDRegressor',SGDRegressor()))
models.append(('PassiveAggressiveRegressor',PassiveAggressiveRegressor()))
# models.append(('HuberRegressor',HuberRegressor()))#STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
# models.append(('PolynomialFeatures',PolynomialFeatures()))#'PolynomialFeatures' object has no attribute 'predict'
models.append(('KernelRidge',KernelRidge()))
models.append(('SVR',SVR()))
models.append(('NuSVR',NuSVR()))
# models.append(('LinearSVR',LinearSVR()))# failed to converge 无法收敛
models.append(('KNeighborsRegressor',KNeighborsRegressor()))
# models.append(('RadiusNeighborsRegressor',RadiusNeighborsRegressor()))# Input contains NaN, infinity or a value too large for dtype('float64').
models.append(('GaussianProcessRegressor',GaussianProcessRegressor()))
models.append(('DecisionTreeRegressor',DecisionTreeRegressor()))
models.append(('BaggingRegressor',BaggingRegressor()))#666666666666666666666666666
models.append(('RandomForestRegressor',RandomForestRegressor()))
models.append(('ExtraTreesRegressor',ExtraTreesRegressor()))#6666
models.append(('AdaBoostRegressor',AdaBoostRegressor()))
models.append(('GradientBoostingRegressor',GradientBoostingRegressor()))
# models.append(('LabelSpreading',LabelSpreading()))#Unknown label type: 'continuous'
# models.append(('IsotonicRegression',IsotonicRegression()))#Isotonic regression input X should be a 1d array or 2d array with 1 feature


print(len(models))
count=0

for name, M in models:
	kfold = KFold(n_splits=3, shuffle=True,random_state=None)
	cv_results = cross_val_score(M, x_train, y_train, cv=kfold, scoring='neg_mean_squared_error')
	results.append(cv_results)
	names.append(name)
	msg = "%s: %f (%f)" % (name, -cv_results.mean(), cv_results.std())
	print(count,'：',msg)
	count+=1

